package com.atguigu.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class LoginController {

    @PostMapping("/user/login")
    public String login(String username, String password, Map<String,Object> map, HttpSession session){
        if ("123456".equals(password)){
            session.setAttribute("loginuser",username);
            //为防止表单重复提交,这里使用重定向到dashboard页面
            return "redirect:/main";
        }else{
            map.put("msg","用户名或密码错误");
            return "index";
        }
    }
}
